# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmysofa
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1
pkgrel=1
pkgdesc="Reader for AES SOFA files to get better HRTFs (mingw-w64)"
arch=('any')
url="https://github.com/hoene/libmysofa/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cunit"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
license=('BSD')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/hoene/libmysofa/archive/v${pkgver}.tar.gz"
        001-mingw-dont-use-nuget.patch
        002-fix-exports.patch
        003-install-import-library.patch)
sha256sums=('e30846be11499c2282ad85edcab7bcca9bf86502df40c343d1f3ff07db17c765'
            'aac5ce1c996f32aaad194cfded9f62d9d3e5d6fba4d5b8bad3cad058cd131650'
            '28727ed8558b324f1f2fe0acbd95d23a5c0ad0bca8b0b3b806cdc0e308753cd6'
            'c328bac9aed3b95ab0d9f0800cedcaadb475649ebff51f3bfd9110d785d3c50b')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-dont-use-nuget.patch
  patch -p1 -i ${srcdir}/002-fix-exports.patch
  patch -p1 -i ${srcdir}/003-install-import-library.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    "../${_realname}-${pkgver}"

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make DESTDIR="${pkgdir}" install
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/
}
